﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Linq.Mapping;
using System.Configuration;
using System.Data.Linq;

namespace DAL.Linq
{
    public static class DataContextFactory
    {
        private static readonly string connectionString;
        private static readonly MappingSource mappingSource;
        static DataContextFactory()
        {
            string connectionStringName = ConfigurationManager.AppSettings.Get("ConnectionStringName");
            connectionString = ConfigurationManager.ConnectionStrings[connectionStringName].ConnectionString;
            DataContext context = new Invoice(connectionString);
            mappingSource = context.Mapping.MappingSource;
        }

        public static Invoice CreateContext()
        {
            return new Invoice(connectionString, mappingSource);
        }
    }
}
